import { Controller, Get, Query } from '@nestjs/common';
import { AppService } from './app.service';
import { map, Observable, timer } from 'rxjs';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  getHello(): Observable<string> {
    return this.appService.getHello();
  }
  @Get('/user/:id')
  getUser(): object {
    return {
      id: 1,
      name: 'John Doe',
      email: 'john@doe.com',
      password: '123456',
    };
  }
  @Get('/delayUser/:id')
  getDelayUser(): Observable<object> {
    return timer(1000).pipe(
      map(() => ({
        id: 1,
        name: 'John Doe',
        email: '',
        password: '',
      })),
    );
  }
  @Get('/getList')
  getList(@Query('word') word: string): Observable<string[]> {
    console.log(`getList word: ${word}`);
    return timer(3000).pipe(map(() => [word, word + '1', word + '2']));
  }
}
